package com.system.module.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.system.common.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.system.framework.aspectj.lang.annotation.Log;
import com.system.framework.aspectj.lang.enums.BusinessType;
import com.system.module.business.domain.PatientUser;
import lombok.extern.slf4j.Slf4j;
import com.system.module.business.service.IPatientUserService;
import com.system.framework.web.controller.BaseController;
import com.system.framework.web.domain.Result;
import com.system.common.utils.poi.ExcelUtil;

/**
 * 患者列表控制层
 *
 * @author mars
 * @date 2023-06-15
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "患者列表接口管理",tags = "患者列表接口管理")
@RequestMapping("/business/user" )
public class PatientUserController extends BaseController {

    private final IPatientUserService iPatientUserService;

    /**
     * 查询患者列表列表
     */
    @ApiOperation(value = "查询患者列表列表")
    @PreAuthorize("@ss.hasPermi('business:user:list')")
    @GetMapping("/list")
    public PageInfo<PatientUser> list(PatientUser patientUser) {
        return iPatientUserService.findPageBySpec(patientUser);
    }

    /**
     * 获取患者列表详细信息
     */
    @ApiOperation(value = "获取患者列表详细信息")
    @PreAuthorize("@ss.hasPermi('business:user:query')" )
    @GetMapping(value = "/query/{id}" )
    public Result getInfo(@PathVariable("id" ) Integer id) {
        return Result.success(iPatientUserService.getById(id));
    }

    /**
     * 新增患者列表
     */
    @ApiOperation(value = "新增患者列表")
    @PreAuthorize("@ss.hasPermi('business:user:add')" )
    @Log(title = "患者列表" , businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody PatientUser patientUser) {
        return Result.success("新增成功",iPatientUserService.add(patientUser));
    }

    /**
     * 修改患者列表
     */
    @ApiOperation(value = "修改患者列表")
    @PreAuthorize("@ss.hasPermi('business:user:edit')" )
    @Log(title = "患者列表" , businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result edit(@RequestBody PatientUser patientUser) {
        return toAjax(iPatientUserService.update(patientUser) ? 1 : 0);
    }

    /**
     * 删除患者列表
     */
    @ApiOperation(value = "删除患者列表")
    @PreAuthorize("@ss.hasPermi('business:user:remove')" )
    @Log(title = "患者列表" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}" )
    public Result remove(@PathVariable Integer[] ids) {
        return toAjax(iPatientUserService.deleteBatch(Arrays.asList(ids)) ? 1 : 0);
    }

    /**
     * 导出患者列表列表
     */
    @ApiOperation(value = "导出患者列表列表")
    @PreAuthorize("@ss.hasPermi('business:user:export')" )
    @Log(title = "患者列表" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public Result export(PatientUser patientUser) {
        List<PatientUser> list = iPatientUserService.getList(patientUser);
        ExcelUtil<PatientUser> util = new ExcelUtil<PatientUser>(PatientUser. class);
        return util.exportExcel(list, "user" );
    }
}
